//
// Created by Crestimes on 24-6-8.
//

#include "OPT.h"

void OPT::doSomethingWhenLimit(int pos, int& out) {
    // 从当前位置开始，看后面最晚出现或不会出现的page，换掉那个
    set<int> temp(pagesNow.begin(), pagesNow.end());
    for (int p = pos + 1; p < pageList.size(); p++) {
        if (temp.size() == 1) break;
        if (temp.count(pageList[p]))temp.erase(pageList[p]);
    }
    out = *temp.begin();
    // 更新pagesNow
    for (int& p : pagesNow) {
        if (p == out)p = pageList[pos];
    }
    // 更新置换信息
    outPageList.push_back(out);
}
